﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public int a=0;
        public Form1()
        {
            if (CheckConnection("http://red-letter.bl.ee/service.php?tipe=get") == false)
            {
                MessageBox.Show("Please connect to internet");
            }
            InitializeComponent();
            this.BackgroundImageLayout = ImageLayout.Stretch;
            dataGridView1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke;
            dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.SandyBrown;
            label1.BackColor = System.Drawing.Color.Transparent;
            label2.BackColor = System.Drawing.Color.Transparent;
        }

        private bool CheckConnection(String URL)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                request.Timeout = 5000;
                request.Credentials = CredentialCache.DefaultNetworkCredentials;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode == HttpStatusCode.OK) return true;
                else return false;
            }
            catch
            {
                return false;
            }
        }

        

        private void button1_Click_1(object sender, EventArgs e)
        {
            String path = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + @"\log.txt";

            using (StreamWriter writer = new StreamWriter(path, true))
            {
                writer.WriteLine(textBox1.Text);
            }
            this.dataGridView1.Rows.Add(++a, userControl11.GetDate , textBox1.Text, richTextBox1.Text);
            textBox1.Text = "";
            richTextBox1.Text = "";
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            
        }
    }
}
